﻿//自动义双击方法
function CustomDbClick() {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    var vid = record.getData("ID");
    if (vid != "") {
        window.parent.$("#tabs").tabs('close', '查看缴款单信息');
        var pagetitle = "查看缴款单信息";
        parent.addTabs(pagetitle, '../Crm/Modules/AddPay.aspx?r=' + Math.random() + '&view=checks&flag=1&WorkflowInsId='+record.getData("WorkFlowInsId")+'&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//自定义新增方法
var queryString = function (key) {
    return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
}
var fnCustomAdd = function () {
    window.parent.$("#tabs").tabs('close', '起草缴款单');
    var pagetitle = "起草缴款单";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//分公司缴款
var fnAddNew2 = function () {
    window.parent.$("#tabs").tabs('close', '起草缴款单');
    var pagetitle = "起草缴款单";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=&WorktaskId=6517f422-70ea-477d-a9b3-07ff55f129eb&WorkflowId=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//总部缴款
var fnAddGain = function () {
    window.parent.$("#tabs").tabs('close', '总部缴款');
    var pagetitle = "总部缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=' + encodeURI(pagetitle) + '&WorktaskId=e64771a5-63d7-4bcc-8037-d9fadadd3214&WorkflowId=864e10a1-eff1-4721-a877-8dabf6d30295');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=' + encodeURI(pagetitle) + '&WorktaskId=e64771a5-63d7-4bcc-8037-d9fadadd3214&WorkflowId=864e10a1-eff1-4721-a877-8dabf6d30295');
    }
    parent.NeedRefreshPage = this;
}
//英才缴款
var fnAddGains = function () {
    window.parent.$("#tabs").tabs('close', '英才缴款');
    var pagetitle = "英才缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?history=' + tempHis + '&title=' + encodeURI(pagetitle) + '&WorktaskId=96586ae8-51fb-4873-82a4-95a712169b5f&WorkflowId=fd37517b-ccf7-4fc5-9cee-18a04118bcfb');
    } else {
        parent.addTabs(pagetitle, '../Crm/BasePages/StartWorkflow.aspx?title=' + encodeURI(pagetitle) + '&WorktaskId=96586ae8-51fb-4873-82a4-95a712169b5f&WorkflowId=fd37517b-ccf7-4fc5-9cee-18a04118bcfb');
    }
    parent.NeedRefreshPage = this;
}
//佣金操作
var fnPlan = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var vState = record.getData("CommissionState");
        if (vState == "2") {
            alert("该记录已操作");
            return;
        } else {
            var SetManagerURL = "../../Crm/Modules/AddCommission.aspx?r=";
            var vid = record.getData(const_entityID);
            if (vid != undefined && vid != "") {
                var pagetitle = "佣金操作";
                document.getElementById("EditUIWindow").src = SetManagerURL + Math.random() + "&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
                YAHOO.example.container.dialog1.show();
                document.getElementById("yui-gen31-button").style.display = "block";
            }
        }
    } else {
        alert("该缴款单还未签核完毕，不能发放佣金");
        return;
     }
}
//价值业绩操作
var fnCheckOrder = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        parent.addTabs('价值业绩申请', '../../Crm/Modules/CrmValueTask.aspx?r=' + Math.random() + '&entity=CrmValue&id=' + record.getData(const_entityID));
        parent.NeedRefreshPage = this;   
    } else {
        alert("该缴款单还未签核完毕，不能申请价值业绩");
        return;
    }

}
//开票信息
var fnAddInvoiceInfo = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var SetManagerURL = "../../Crm/Modules/AddInvoiceInfo.aspx?r=";
        var vid = record.getData(const_entityID);
        if (vid != undefined && vid != "") {
            var pagetitle = "发票信息";
            document.getElementById("EditUIWindow").src = SetManagerURL + Math.random() + "&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "block";
        }
//        parent.addTabs('发票信息', '../../Crm/Modules/AddInvoiceInfo.aspx?r=' + Math.random() + '&entity=CrmValue&id=' + record.getData(const_entityID));
//        parent.NeedRefreshPage = this;
    } else {
        alert("该缴款单还未签核完毕，不能填写发票信息");
        return;
    }
}
//审核
var fnCheck = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var SetManagerURL = "../../Crm/Modules/AddInvoiceInfo.aspx?r=";
        var vid = record.getData(const_entityID);
        if (vid != undefined && vid != "") {
            var pagetitle = "审核操作";
            document.getElementById("EditUIWindow").src = SetManagerURL + Math.random() + "&view=check&id=" + vid + "&title=" + encodeURI(pagetitle) + "";
            YAHOO.example.container.dialog1.show();
            document.getElementById("yui-gen31-button").style.display = "block";
        }

//        parent.addTabs('发票信息', '../../Crm/Modules/AddInvoiceInfo.aspx?r=' + Math.random() + '&entity=CrmValue&id=' + record.getData(const_entityID));
//        parent.NeedRefreshPage = this;
    } else {
        alert("该缴款单还未签核完毕，不能复核");
        return;
    }
}
//复核
var fnNoPassAgainCheck = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var vid = record.getData("ID");
        if (vid != "") {
            if (confirm("您确定该缴款单复核【不通过】吗？")) {
                var SaveUrl = "../../EditWidows/OrganizationalManager/DataProcessin.aspx" + "?r=" + Math.random() + "&CheckValue=2&action=update&entity=CrmCheckPay&json=&id=" + vid;
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            YAHOO.example.container.dialog3.hide();
                            alert("操作成功!");
                            RefreshData();
                            return;
                        } else {
                            alert(str);
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
            }
            //            window.parent.$("#tabs").tabs('close', '复核缴款单信息');
            //            var pagetitle = "复核缴款单信息";
            //            parent.addTabs(pagetitle, '../Crm/Modules/AddPay.aspx?r=' + Math.random() + '&view=AgainCheck&flag=1&entity=' + const_EditEntity + '&id=' + vid + '&title=' + encodeURI(pagetitle));
            //            parent.NeedRefreshPage = this;
        }

        //        parent.addTabs('发票信息', '../../Crm/Modules/AddInvoiceInfo.aspx?r=' + Math.random() + '&entity=CrmValue&id=' + record.getData(const_entityID));
        //        parent.NeedRefreshPage = this;
    } else {
        alert("该缴款单还未签核完毕，不能复核");
        return;
    }
}
//复核
var fnPassAgainCheck = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var stName = record.getData("StateName");
    if (stName == "结案") {
        var vid = record.getData("ID");
        if (vid != "") {
            if (confirm("您确定该缴款单复核【通过】吗？")) {
                var SaveUrl = "../../EditWidows/OrganizationalManager/DataProcessin.aspx" + "?r=" + Math.random() + "&CheckValue=1&action=update&entity=CrmCheckPay&json=&id=" + vid;
                YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                    success: function (res) {
                        try {
                            var str = res.responseText;
                            if (str == "1") {
                                YAHOO.example.container.dialog3.hide();
                                alert("操作成功!");
                                RefreshData();
                                return;
                            } else {
                                alert(str);
                            }
                        }
                        catch (e) {
                        }
                        finally {
                        }
                    },
                    failure: function (error) {
                        alert("数据错误：" + error.statusText);
                    }
                }, null);

            }
        }
    } else {
        alert("该缴款单还未签核完毕，不能复核");
        return;
    }
}
//直接缴款方法
var fnAddNew1 = function () {
    window.parent.$("#tabs").tabs('close', '现场缴款');
    var pagetitle = "现场缴款";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs(pagetitle, '../crm/Modules/AddPay.aspx?history=' + tempHis + '&flag=0&type=directPay&title=&entity=CrmPay&wtid=6517f422-70ea-477d-a9b3-07ff55f129eb&wfid=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    } else {
        parent.addTabs(pagetitle, '../crm/Modules/AddPay.aspx?flag=0&type=directPay&title=&entity=CrmPay&wtid=6517f422-70ea-477d-a9b3-07ff55f129eb&wfid=17972549-9867-4ad8-8cdf-e6141a9af6f0');
    }
    parent.NeedRefreshPage = this;
}
//自定义修改方法
var fnCustomEdit = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    //if (record == null || record.getData("CheckName") != "") {
    //alert("请选择一条现场缴款单（核算人员为空的记录）");
    if (record == null) {
        alert("请选择一条缴款单");
        return;
    }
    window.parent.$("#tabs").tabs('close', '编辑缴款单信息');
    var cid = record.getData("CustomerId");
    var pagetitle = "编辑缴款单信息";
    if (queryString("condition") != null || queryString("condition") == "") {
        var tempHis = queryString("condition");
        tempHis = tempHis.substr(0, 4);
        parent.addTabs('编辑缴款单信息', '../Crm/Modules/AddPay.aspx?history=' + tempHis + '&flag=1&type=directPay&edit=update&r=' + Math.random() + '&cid=' + cid + '&title=' + encodeURI(pagetitle) + '&entity=CrmPay&id=' + record.getData(const_entityID));
    } else {
        parent.addTabs('编辑缴款单信息', '../Crm/Modules/AddPay.aspx?flag=1&type=directPay&edit=update&r=' + Math.random() + '&cid=' + cid + '&title=' + encodeURI(pagetitle) + '&entity=CrmPay&id=' + record.getData(const_entityID));
    } parent.NeedRefreshPage = this;

}
//自定义删除方法
//var fnCustomDeleteData = function () {
//}

if (typeof ($) == "undefined") { //屏蔽右键
    parent.unContextMenu(document);
    /*$(document).ready(function () { 
    if (typeof (parent.unContextMenu) == "function") {
    parent.unContextMenu(document);
    }
    if (typeof (parent.parent.unContextMenu) == "function") {
    parent.parent.unContextMenu(document);
    }
    });*/
}
if (typeof (YAHOO) == "undefined") {
    parent.unContextMenu(document);
}
//备注过滤
var fnExplain=function(elCell, oRecord, oColumn, sData) {
    sData.replace("[BR]", "");
    if (sData.length > 20) {
        elCell.innerHTML = sData.substring(0, 20) + "..." + "<a href='javascript:CustomDbClick()'>详细</a>";
    }
    else {
        elCell.innerHTML = sData;
    }
};
//格式化佣金状态
var fnPay = function (elCell, oRecord, oColumn, sData) {
    if (sData == "2") {
        elCell.innerHTML = "<font color='red'>已发放完成</font>";
    } else if (sData == "3") {
        elCell.innerHTML = "<font color='red'>已发放部分</font>";
    } else {
        elCell.innerHTML = "<font color='red'>还未发放</font>";;
    }
};
//格式化时间
var fnDate = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0001-01-01 ") {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = sData;
    }
};
//自定义删除方法
var fnCustomDeleteData = function () {
    var Url = "AjaxData/CustomOperating.aspx";
    var recordID = myDataTable.getSelectedRows()[0];
    var record = myDataTable.getRecord(recordID);
    var vid = record.getData(const_entityID);
    if (vid != "") {
        var SaveUrl = Url + "?r=" + Math.random() + "&action=delete&entity=V_CrmPay&id=" + vid;
        YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
            success: function (res) {
                try {
                    var str = res.responseText;
                    if (str == "1") {
                        YAHOO.example.container.dialog3.hide();
                        alert("删除成功!");
                        RefreshData();
                        return;
                    } else {
                        alert(str);
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
}